using System;
using UnityEngine;

namespace Script.SteerBehaviour
{
    [RequireComponent(typeof(Rigidbody2D))]
    public class SteerBehaviour : MonoBehaviour
    {
        public float maxVelocity;
        public float maxAcceleration;

        private Rigidbody2D rb;

        private void Awake()
        {
            rb = GetComponent<Rigidbody2D>();
        }

        public void Steer(Vector2 linearAcc)
        {
            rb.velocity += linearAcc * Time.deltaTime;
            if (rb.velocity.magnitude > maxVelocity)
            {
                rb.velocity = rb.velocity.normalized * maxVelocity;
            }
        }
        
        public Vector3 Seek(Vector3 targetPos, float maxSeekAcc)
        {
            Vector3 acceldirection = targetPos - transform.position;
            acceldirection.Normalize();
            acceldirection *= maxSeekAcc;
            return acceldirection;
        }

        public Vector3 Seek(Vector3 targetPoS)
        {
           return Seek(targetPoS, maxAcceleration);
        }
    }
}